Repository navigation
metrics-plugin: Label lightning_funds_output_msat by output status and reservation - #16
Open
Nazarevsky wants to merge 4 commits into
Open
Nazarevsky wants to merge 4 commits into
Nazarevsky wants to merge 4 commits into
Conversation
lightning_funds_output_msat adds up every listfunds output: unconfirmed, immature and reserved ones included. That overstates what the node can spend now, e.g. to open a channel, so it can't drive a low-funds alert. Keep the sum per output status (unconfirmed, confirmed, spent, immature) and per reserved flag in FundsSnapshot instead of one total. The exported series are unchanged in this commit: lightning_funds_output_msat and lightning_funds_total_msat still show the same total, now computed from the split. Unit tests cover confirmed, unconfirmed, reserved and immature outputs, check that the parts add up to the old total, and that the status order matches the labels the next commit exports.
Export lightning_funds_output_msat as one series per output status
(unconfirmed, confirmed, spent, immature) and reserved flag (true,
false), so on-chain funds that can be spent now are a query:
lightning_funds_output_msat{status="confirmed", reserved="false"}
All 8 series are exported on every scrape, at 0 when empty, so none
goes absent on an empty wallet. lightning_funds_total_msat keeps its
value.
This changes an existing series: a query on lightning_funds_output_msat
without sum() now returns 8 series instead of 1, and an alert like
`lightning_funds_output_msat < X` fires on the zero ones. Use
`sum without (status, reserved) (lightning_funds_output_msat)` for the
old total.
A collector test checks the exported series, labels and values.
Describe the status and reserved labels in the README's Funds section, note that spent stays at 0 (listfunds is called without spent), and give the queries for spendable on-chain funds and for the old total.
Add metrics-plugin/dashboards/cln-metrics.json, a Grafana dashboard (uid cln-metrics) for the series the metrics plugin exports.
Nazarevsky
force-pushed
the
nazarevsky/metric-onchain-reserved-funds
branch
from
November 25, 2026 15:22
05c0e37 to
414fded
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Currently on the master branch
lightning_funds_output_msatshows the mixed onchain balance including both reserved and unreserved outputs.lightning_funds_output_msatadds up everylistfundsoutput, including unconfirmed, immature and reserved ones. That overstates what the node can spend now. For example, inputs reserved by a channel open that's in progress still count, so a "low on-chain funds" alert built on it fires too late.This PR adds two labels to the metric, both taken from each
listfundsoutput:status:unconfirmed,confirmed,spent,immaturereserved:true,falseOn-chain funds the node can spend now become a query:
Also, Grafana dashboard for outputing all those metrics was missing - adding it in this PR.
Changes
cache.rs:FundsSnapshotkeeps the sum for each status and reserved flag instead of one total.metrics.rs:lightning_funds_output_msatis now exported with thestatusandreservedlabels. All 8 combinations are exported on every scrape, at 0 when empty, so no series disappears when the wallet is empty.lightning_funds_total_msatis unchanged and keeps its value.README.md: documents the labels, plus queries for spendable funds and for the old total.spentis always 0, because the plugin callslistfundswithoutspent. It's exported anyway, so the label covers every statuslistfundscan return.Breaking change
lightning_funds_output_msatchanges from one series to 8 labelled series.lightning_funds_output_msat < Xwould also fire on the zero-valued series.To get the old value:
sum()works with both the old and the new version, so dashboards can be updated before upgrading.Testing
cache.rsunit tests: confirmed, unconfirmed, reserved and immature outputs land in the right status/reserved bucket, and the buckets add up to the old total.lightning_funds_total_msat.cargo test -p metrics-plugin(11 passed),cargo clippy --all-targets --all-features -- -D warningsandcargo fmt --checkare clean.